package com.kedou.sdk.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.kedou.sdk.params.RedpackageResponseParams;
import com.kedou.sdk.utils.ResUtils;

public class RedPackageBindFragment extends Fragment  implements View.OnClickListener {

//    private EditText mIdentificationNameEt;
//    private EditText mIdentificationCardEt;
//
    private Button mBindPhoneBtn;
    private EditText nameEdit,accountEdit;

//    public static RedPackageFragment newInstance(Bundle bundle) {
//        RedPackageFragment fragment = new RedPackageFragment();
//        fragment.setArguments(bundle);
//        return fragment;
//    }

    private ChangeFragmentLister changeFragmentLister;
    private ImageView backImage;


    public RedPackageBindFragment(ChangeFragmentLister changeFragment){
        this.changeFragmentLister = changeFragment;
    }

    @Override
    public void onResume() {
        super.onResume();
        setData();
    }

    private void setData(){
        if(data==null)return;
        if(data.getIs_bind_zfb()==1){
            nameEdit.setText(data.getReal_name());
            accountEdit.setText(data.getZfb_account());
        }
    }

    private RedpackageResponseParams.RedpackageResponseData data ;
    public void updateData(RedpackageResponseParams.RedpackageResponseData data ){
        this.data = data;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        int resource = ResUtils.getLayoutIdentifier(getActivity(), "hnssn_fragment_redpackage_bind");
        View contentView = inflater.inflate(resource, null);
        setView(contentView);

        return contentView;
    }

    private void setView(View view){
        view.setOnClickListener(this);
        backImage = view.findViewById(ResUtils.getViewIdentifier(getActivity(), "fragment_redpackagetixian_back"));
        backImage.setOnClickListener(this);
        mBindPhoneBtn = view.findViewById(ResUtils.getViewIdentifier(getActivity(), "activity_redpackage_bind_confirm"));
        mBindPhoneBtn.setOnClickListener(this);
        nameEdit = view.findViewById(ResUtils.getViewIdentifier(getActivity(), "activity_redpackage_bind_name"));
        accountEdit = view.findViewById(ResUtils.getViewIdentifier(getActivity(), "activity_redpackage_bind_card"));

    }

    @Override
    public void onClick(View v) {
        if( v == backImage){
            changeFragmentLister.changeToTixian();
        }else if (v == mBindPhoneBtn){
            String name = nameEdit.getText().toString().trim();
            String account = accountEdit.getText().toString().trim();
            if(TextUtils.isEmpty(name)){
                Toast.makeText(getActivity(),"请输入姓名",Toast.LENGTH_SHORT).show();
            }else if (TextUtils.isEmpty(account)){
                Toast.makeText(getActivity(),"请输入支付宝账号",Toast.LENGTH_SHORT).show();
            }else {
                changeFragmentLister.bindAlipay(name,account);
            }
        }
    }
}
